﻿

using CloudSail.Exam.InfrastructureDto.Response.ResultDto;
using Main.Extend;
using Main.Server;
using Main.Service;
using Microsoft.Extensions.Configuration;

namespace CloudSail.Exam.Service.Instance
{
    public class ApiResultService
    {
        public BaseServer _Server;
        public IConfiguration _Config;
        private BaseService baseService;

        public ApiResultService(BaseServer baseServer,IConfiguration configuration)
        {
            _Server = baseServer;
            _Config = configuration;
            
        }

        public ApiResultService(BaseService baseService)
        {
            this.baseService = baseService;
        }

        /// <summary>
        /// 返回状态结果
        /// </summary>
        /// <param name="Code">状态</param>
        /// <returns></returns>
        public static ApiResult GetResult(ApiCode Code)
        {
            string Msg = "";
            switch (Code)
            {
                case ApiCode.Ok:
                    Msg = "操作成功";
                    break;
                case ApiCode.Fail:
                    Msg = "操作失败";
                    break;
                case ApiCode.other:
                    Msg = "其他操作";
                    break;
            }

            return new ApiResult()
            {
                Code = Code,
                Msg = Msg
            };
        }
        /// <summary>
        /// 返回状态 和 数据
        /// </summary>
        /// <param name="Code">状态</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult GetResult(ApiCode Code, object data)
        {
            string Msg = "";
            switch (Code)
            {
                case ApiCode.Ok:
                    Msg = "操作成功";
                    break;
                case ApiCode.Fail:
                    Msg = "操作失败";
                    break;
                case ApiCode.other:
                    Msg = "其他操作";
                    break;
            }

            return new ApiResult()
            {
                Code = Code,
                Msg = Msg,
                data = data
            };
        }

        /// <summary>
        /// 返回状态和信息结果
        /// </summary>
        /// <param name="Code">状态</param>
        /// <param name="Msg">信息</param>
        /// <returns></returns>
        public static ApiResult GetResult(ApiCode Code, string Msg)
        {
            return new ApiResult()
            {
                Code = Code,
                Msg = Msg,
            };
        }

        /// <summary>
        /// 返回所有结果集
        /// </summary>
        /// <param name="Code">状态代码</param>
        /// <param name="Msg">信息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult GetResult(ApiCode Code, string Msg, object data)
        {
            return new ApiResult()
            {

                Code = Code,
                Msg = Msg,
                data = data
            };
        }

        #region 返回 OK
        /// <summary>
        /// 返回 OK 不带消息和数据
        /// </summary>
        /// <returns></returns>
        public static ApiResult Ok()
        {
            return new ApiResult()
            {
                Code = ApiCode.Ok,
                Msg = "操作成功",
            };
        }
        /// <summary>
        /// 返回 OK 带数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Ok(object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.Ok,
                Msg = "操作成功",
                data = data

            };
        }
        /// <summary>
        /// 返回 OK 带消息
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <returns></returns>
        public static ApiResult Ok(string Msg)
        {
            return new ApiResult()
            {
                Code = ApiCode.Ok,
                Msg = Msg,
            };
        }

        /// <summary>
        /// 返回 OK 带消息 和 数据
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Ok(string Msg, object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.Ok,
                Msg = Msg,
                data = data

            };
        }
        #endregion

        #region 返回 Fail
        /// <summary>
        /// 返回 Fail 不带消息和数据
        /// </summary>
        /// <returns></returns>

        public static ApiResult Fail()
        {
            return new ApiResult()
            {
                Code = ApiCode.Fail,
                Msg = "操作失败",
            };
        }
        /// <summary>
        /// 返回 Fail 带数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Fail(object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.Fail,
                Msg = "操作失败",
                data = data

            };
        }
        /// <summary>
        /// 返回 Fail 带消息
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <returns></returns>
        public static ApiResult Fail(string Msg)
        {
            return new ApiResult()
            {
                Code = ApiCode.Fail,
                Msg = Msg,
            };
        }

        /// <summary>
        /// 返回 Fail 带消息 和 数据
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Fail(string Msg, object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.Fail,
                Msg = Msg,
                data = data

            };
        }
        #endregion

        #region 返回 other


        /// <summary>
        /// 返回 other 带消息
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <returns></returns>
        public static ApiResult Other(string Msg)
        {
            return new ApiResult()
            {
                Code = ApiCode.other,
                Msg = Msg,
            };
        }

        /// <summary>
        /// 返回 other 带消息 和 数据
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Other(string Msg, object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.other,
                Msg = Msg,
                data = data

            };
        }

        #endregion

        #region 返回 Error
        /// <summary>
        /// 返回 Error 不带消息和数据
        /// </summary>
        /// <returns></returns>
        public static ApiResult Error()
        {
            return new ApiResult()
            {
                Code = ApiCode.error,
                Msg = "系统异常",
            };
        }
        /// <summary>
        /// 返回 Error 带数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Error(object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.error,
                Msg = "系统异常",
                data = data

            };
        }
        /// <summary>
        /// 返回 Error 带消息
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <returns></returns>
        public static ApiResult Error(string Msg)
        {
            return new ApiResult()
            {
                Code = ApiCode.error,
                Msg = Msg,
            };
        }

        /// <summary>
        /// 返回 Error 带消息 和 数据
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult Error(string Msg, object data)
        {
            return new ApiResult()
            {
                Code = ApiCode.error,
                Msg = Msg,
                data = data

            };
        }
        #endregion


    }
}
